package com.cib.icarus.desensitize;


import com.cib.icarus.desensitize.wrapper.DesWrapper;
import com.cib.icarus.desensitize.wrapper.internals.FastjsonDesWrapper;
import com.cib.icarus.desensitize.wrapper.internals.GsonDesWrapper;
import com.cib.icarus.desensitize.wrapper.internals.JacksonDesWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 脱敏工具门面，提供默认的DesWrapper实现。
 * 分别是JacksonDesWrapper、GsonDesWrapper、FastjsonDesWrapper。
 * 这三类门面的将根据当前运行环境是否导入了对应包来决定是否处理。
 *
 * @author goomba
 */
public class DesensitizeFacade {

    private static final Logger logger = LoggerFactory.getLogger(DesensitizeFacade.class);


    public static DesWrapper getInternalDesWrapper() {
        DesWrapper desWrapper = null;
        if (JsonChecker.isJacksonPresent()) {
            desWrapper = JacksonDesWrapper.nonNullMapper();
            logger.warn("load default DesWrapper {} to handle data desensitization ", desWrapper.getClass().getName());
            return desWrapper;
        }

        if (JsonChecker.isGsonPresent()) {
            desWrapper = GsonDesWrapper.getInstance();
            logger.warn("load default DesWrapper {} to handle data desensitization ", desWrapper.getClass().getName());
            return desWrapper;
        }

        if (JsonChecker.isFastjsonPresent()) {
            desWrapper = FastjsonDesWrapper.getInstance();
            logger.warn("load default DesWrapper {} to handle data desensitization ", desWrapper.getClass().getName());
            return desWrapper;
        }

        logger.warn("No DesWrapper implementations found, " +
                "DesensitizeFacade default supports JacksonDesWrapper, GsonDesWrapper and FastjsonDesWrapper. " +
                "If you want to handle data desensitization by yourself, you can extend {}. ", DesWrapper.class.getName());
        return desWrapper;
    }
}
